package com.hudongwx.my_shian.adapter.homeAdapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;

import java.util.List;

/**
 * Author:曾传标
 * time：16-12-13 下午6:42
 */
public class MyImgPlayAdapter extends PagerAdapter {


    Context context;
    List<ImageView> imgData;


    public MyImgPlayAdapter( Context context,List<ImageView> imgData) {

        this.context = context;
        this.imgData = imgData;
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        position %= imgData.size();

        if (position<0){
            position = position+imgData.size();
        }

        ImageView  imageView = imgData.get(position);

        //
        ViewParent vp = imageView.getParent();

        if (vp!=null){
            ViewGroup group = (ViewGroup) vp;
            group.removeView(imageView);
        }

        container.addView(imageView);

        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

    }
}
